<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>相册管理</title>
<link rel="stylesheet" type="text/css"
    href="../../js/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css"
    href="../../js/easyui/themes/icon.css">
<link href="../../js/uploadify/uploadify.css" type="text/css" rel="stylesheet" />   
<script type="text/javascript" src="../../js/easyui/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../js/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../js/easyui/locale/easyui-lang-zh_CN.js"></script>
<script>

function createAlbum() {
    $("#albumForm").form('submit', {
        url: "add_or_update_album.action",
        onSubmit:function() {
            return $(this).form('validate');
        },
        success:function(data) {
        	$('#galleryGrid').datagrid('reload');
            closeAlbumForm();
        }
    });
}

function closeAlbumForm() {
    $('#albumForm').form('clear');
    $('#itemEditorDialog').dialog('close');
}


function addAlbum() {
	$('#albumForm').form('load', {
		'album.id':-1,
		'album.priority':0,
        'album.owner':1
    });
    $('#itemEditorDialog').show();
    $('#itemEditorDialog').dialog({
        title:'添加栏目',
        modal:true
    });
}

function editAlbum(index) {
	$('#galleryGrid').datagrid('selectRow', index);
	var node = $('#galleryGrid').datagrid('getSelected');
	
    $('#albumForm').form('load', {
        'album.column.id':node.columnId,
        'album.id':node.id,
        'album.title':node.title,
        'album.viceTitle':node.viceTitle,
        'album.keywords':node.keywords,
        'album.description':node.description,
        'album.cover':node.cover,
        'album.clickNumber':node.clickNumber,
        'album.priority':node.priority,
        'album.owner':1
    });

    $('#itemEditorDialog').show();
    $('#itemEditorDialog').dialog({
        name:'编辑栏目',
        modal:true
    });
}

function deleteAlbum(index) {
	$('#galleryGrid').datagrid('selectRow', index);
	var node = $('#galleryGrid').datagrid('getSelected');
	
    $('#albumForm').form('load', {
        'album.id':node.id,
        'album.title':node.title
    });
    $.messager.confirm('确认','确认要删除吗?',function(fn){   
        if (fn){        	
        	$("#albumForm").form('submit', {
                url: "delete_album.action",
                success:function(data) {
                    $('#galleryGrid').datagrid('reload');
                }
            });   
        }   
    });  
}

function queryAlbums() {
    var galleryTitle = $("#galleryTitle").val();
    var galleryColumn = $("input[name='galleryColumn']").val();

    var queryParams = $('#galleryGrid').datagrid('options').queryParams;
    queryParams.galleryTitle = galleryTitle;
    queryParams.galleryColumn = galleryColumn;
    $('#galleryGrid').datagrid('options').queryParams = queryParams;
    //alert($('#galleryGrid').datagrid('options').queryParams[0]);
    $("#galleryGrid").datagrid('reload');
}

function recommendAlbum() {
    var node = $('#galleryGrid').datagrid('getSelected');
    var rows = $('#galleryGrid').datagrid('getSelections');

    if (rows.length != 1) {
        $.messager.alert('警告', '请选择一条记录!', 'warning');
        return;
    }
    $('#albumForm').form('load', {
        'album.column.id':node.columnId,
        'album.id':node.id,
        'album.title':node.title,
        'album.description':node.description,
        'album.cover':node.cover,
        'album.priority':1,
        'album.owner':1
    });
    $("#albumForm").form('submit', {
        url: "add_or_update_album.action",
        success:function(data) {
            $('#galleryGrid').datagrid('reload');
        }
    });  
}

function cancelRecommendAlbum() {
    var node = $('#galleryGrid').datagrid('getSelected');
    var rows = $('#galleryGrid').datagrid('getSelections');

    if (rows.length != 1) {
        $.messager.alert('警告', '请选择一条记录!', 'warning');
        return;
    }
    $('#albumForm').form('load', {
    	'album.column.id':node.columnId,
        'album.id':node.id,
        'album.title':node.title,
        'album.description':node.description,
        'album.cover':node.cover,
        'album.priority':0,
        'album.owner':1
    });
    $("#albumForm").form('submit', {
        url: "add_or_update_album.action",
        success:function(data) {
            $('#galleryGrid').datagrid('reload');
        }
    });  
}

$(function() {
	$('#galleryGrid').datagrid( {
			url : 'find_albums.action',
			singleSelect : true,
			idField:'id',
			rownumbers:true,
			columns : [ [ 
				//{field: 'id', title: 'ID', width: 80},
				{field: 'columnName', title: '栏目', width: 80},
				{field: 'columnId', title: '栏目', width: 80,  hidden: true},
			 	{field: 'title', title: '标题', width: 130, formatter: function(value, rowData, rowIndex){				 	
				 	var text = " <a target='_blank' href='http://pic.fengsung.com/g-" + rowData.id + ".html' >" + value +"</a>";
                    return text;
                }},
			 	{field: 'viceTitle', title: '副标题', width: 130},
			 	{field: 'keywords', title: '关键字', width: 130},
			 	{field: 'clickNumber', title: '浏览量', width: 50},
			 	{field: 'date', title: '修改时间', width: 100},
			 	{field: 'priority', title: '级别', width: 55,formatter: function(value, rowData, rowIndex){
				 		if (value == '0') {
	                        return '普通';
	                    } else if (value == '2') {
	                        return '栏目推荐';
	                    } else if (value == '4') {
	                        return '首页推荐';
	                    } else if (value == '8') {
	                        return '首页滚动';
	                    }
				 	}},		
			 	{field: 'description', title: '介绍', width: 200}, 			 	
			 	{field: 'opt', title: '操作', formatter: function(value, rowData, rowIndex){
					 	var text="<a href='album_index.action?album.id=" + rowData.id + "'>进入</a>";
					 	text = text + " <a href='#' onclick=\"editAlbum(\'" + rowIndex + "\')\"" + ">编辑</a>";
                    <s:if test="1 == #session._user_role_">
                            text = text + " <a href='#' onclick=\"deleteAlbum(\'" + rowIndex + "\')\"" + ">删除</a>";
                    </s:if>
	                    return text;
	                }}
			] ],
			pagination:true,
			toolbar:[
			            {
			                text:'添加相册',
			                iconCls:'icon-add',
			                handler:function() {
			                    addAlbum();
			                }
			            }
			       ]
	});
});
</script>
</head>
<body>

<div id="p" class="easyui-panel" title="图库搜索" icon="icon-search" style="height:80px;padding:10px;">
	<table>
		<tr>
			<td><label>标题:</label></td>
			<td><input name="galleryTile" id="galleryTitle"/></td>
			<td><label>栏目:</label></td>
			<td><select id="columnCombo" class="easyui-combotree" name="galleryColumn"
                            url="find_column_combotree.action"
                            cascadeCheck="false" style="width:200px;"></select></td>

			<td style="width:30px"></td>
			<td><a class="easyui-linkbutton" onclick="javascript: queryAlbums()">搜索</a></td>
		</tr>
	</table>
</div>
<table id="galleryGrid"></table>

<div id="coverDialog" icon="icon-save" title="封面管理"
    style="height: 400; width: 400; display: none; padding: 5px;">
    <form>
        <input id="uploadify" name="uploadify" type="file" />
        <input id="uploadInit" name="uploadInit"  value="0">
    </form>
</div>
<div id="itemEditorDialog" icon="icon-save" title="相册管理"
	style="height: 400; width: 400; display: none; padding: 5px;">
<form method="post" id="albumForm" name="albumForm">
<table>
    <tr>
        <td><label>栏目: </label></td>
        <td>
        <input id="column" name="album.column.id" class="easyui-combotree" url="find_column_combotree.action" style="width:200px;">
        </td>
    </tr>
	<tr>
		<td><label>相册标题：</label></td>
		<td><input class="easyui-validatebox" id="name"
			name="album.title" /></td>
	</tr>
	<tr>
		<td><label>相册副标题：</label></td>
		<td><input class="easyui-validatebox" id="viceName"
			name="album.viceTitle" /></td>
	</tr>
	<tr>
		<td><label>关键字：</label></td>
		<td><input class="easyui-validatebox" id="keywords"
			name="album.keywords" /></td>
	</tr>
	<tr>
		<td><label>相册描述：</label></td>
		<td>
		<textarea class="easyui-validatebox" id="description"
			name="album.description"></textarea></td>
	</tr>
	<tr>
        <td><label>优先级：</label></td>
		<td><select class="easyui-validatebox" name="album.priority">
		    <option value="0">普通</option>  
			<option value="8">首页滚动</option>
			<option value="4">首页推荐</option>
			<option value="2">栏目推荐</option>
		</select></td>
	</tr>
</table>
<div class="toolbar" style="padding: 10px;">
	<a href="#" onclick="createAlbum()" class="easyui-linkbutton" iconCls="icon-ok">确定</a>
	<a href="#" onclick="closeAlbumForm()" class="easyui-linkbutton" iconCls="icon-cancel">取消</a>
</div>
	<input type="hidden" name="album.owner" value="1" />
	<input type="hidden" name="album.cover" />
	<input type="hidden" name="album.clickNumber" value="0" />
	<input type="hidden" name="album.id" value="-1" /></form>
</div>
</body>
</html>